#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:stone
@file:github.py
@time:2021/08/12
"""

from common.config import Config
from common.net import Net


# curl -X GET --header 'Content-Type: application/json;charset=UTF-8' -i -u stone-ch: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 'https://api.github.com/search/repositories?q=blockchain&page=1&per_page=1&order=desc'
class Github:
    conf = None

    def __init__(self):
        self.conf = Config()

    def getRepoBySearch(self, query_word, page, per_page, order):
        auth = '"token ' + self.conf.github_token + '"'
        headers = {"Authorization": auth,
                   "Content-Type": "application/json;charset=UTF-8"}

        query_word = "q=" + query_word
        page = "page=" + page
        per_page = "per_page=" + per_page
        order = "order=" + order
        url = "https://api.github.com/search/repositories"
        url += "?" + query_word
        url += "&" + page
        url += "&" + per_page
        url += "&" + order
        n = Net()
        return n.send(url, headers, "get", "")
